package cn.fw.community.adapter.vo;

import cn.hutool.extra.spring.SpringUtil;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.HashMap;
import java.util.Map;
import lombok.Data;
import org.springframework.core.ResolvableType;

/**
 * @author cn
 * @version 1.0
 * @description
 * @date 2022/8/9 18:00
 */
@Data
public class RequestDto<T> {

  private Long id;
  private String name;


  private Map<String, Object> extInfo = new HashMap<>();

  private T extInfoObj;

  public T getExtInfoObj() {
    return (T) SpringUtil.getBean(ObjectMapper.class).convertValue(extInfo,
        ResolvableType.forClass(this.getClass()).getSuperType().resolveGeneric(0));
  }

  @JsonAnySetter
  public void setExtInfo(String name, Object value) {
    extInfo.put(name, value);
  }
}
